package cn.gd.pojo;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.List;

/**
 * 上传文件设置
 */
public class UploadSettings {
    /**
     *
     */
    private Integer settingId;

    /**
     * 文件大小限制，单位为MB
     */
    private Integer fileSizeLimit;

    /**
     * 允许的文件类型，以逗号分隔
     * 取数据
     */
    private List<String> allowedFileTypes;

    /**
     * 存数据
     */
    private String StringAllowedFileTypes;

    public Integer getSettingId() {
        return settingId;
    }

    public void setSettingId(Integer settingId) {
        this.settingId = settingId;
    }

    public Integer getFileSizeLimit() {
        return fileSizeLimit;
    }

    public void setFileSizeLimit(Integer fileSizeLimit) {
        this.fileSizeLimit = fileSizeLimit;
    }

    public List<String> getAllowedFileTypes() {
        if (allowedFileTypes == null && StringAllowedFileTypes != null) {
            try {
                // 使用 Jackson 库将字符串转换为 List 集合
                allowedFileTypes = new ObjectMapper().readValue(StringAllowedFileTypes, new TypeReference<List<String>>(){});
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return allowedFileTypes;
    }

    public void setAllowedFileTypes(List<String> allowedFileTypes) {
        this.allowedFileTypes = allowedFileTypes;
    }

    public String getStringAllowedFileTypes() {
        return StringAllowedFileTypes;
    }

    public void setStringAllowedFileTypes(String stringAllowedFileTypes) {
        StringAllowedFileTypes = stringAllowedFileTypes;
    }
}
